
<template>
  <elm-page-bb class="elm-list-edit">
    <elm-page-tb :splite="false" :splite-show="false">
      <template #top hei>
        <right>
          <el-button-group>
            <el-button size="mini" @click="add">新增</el-button>
          </el-button-group>
        </right>
      </template>
      <elm-table ref="table" url="/business/my/ei/credentials/GetData" :post-data="postData" :page-size="9999" height="100%">
        <el-table-column :label="request.type" align="center">
          <template v-slot="scope">
            <el-form size="small" label-width="120px">
            <elm-row>
              <el-form-item :label="request.type=='资格证书'?'证书名称':'职称名称'">
                <el-input v-model="scope.row.name"></el-input>
              </el-form-item>
              <el-form-item label="编号">
                <el-input v-model="scope.row.cred_key"></el-input>
              </el-form-item>
            </elm-row>
              <elm-row>
                <el-form-item label="发证机构">
                  <el-input v-model="scope.row.cred_org"></el-input>
                </el-form-item>
                <el-form-item label="签发日期">
                  <el-date-picker v-model="scope.row.cred_date"  value-format="yyyy-MM-dd" type="date" style="width: 100%">
                  </el-date-picker>
                </el-form-item>
              </elm-row>
              <elm-row>
                <el-form-item label="起始有效期">
                  <el-date-picker v-model="scope.row.valid_sdate"  value-format="yyyy-MM-dd" type="date" style="width: 100%">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="截止有效期">
                  <el-date-picker v-model="scope.row.valid_edate"  value-format="yyyy-MM-dd" type="date" style="width: 100%">
                  </el-date-picker>
                </el-form-item>
              </elm-row>
              <elm-row v-if="request.type=='专业职称'">
                <el-form-item label="专业">
                  <el-input v-model="scope.row.major"></el-input>
                </el-form-item>
                <el-form-item label="备注">
                  <el-input v-model="scope.row.remark"></el-input>
                </el-form-item>
              </elm-row>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="80px" align="center">
          <template v-slot="scope">
            <el-button @click="del(scope.row)"  type="text" size="mini">删除</el-button>
          </template>
        </el-table-column>
      </elm-table>
    </elm-page-tb>
    <template #bottom>
      <el-button type="success" size="small" @click="submit">立即保存</el-button>
      <el-button size="small" @click="close">取消</el-button>
    </template>
  </elm-page-bb>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      postData:{type:null,ei_id:null}
    }
  },
  created() {
    this.postData.ei_id=this.request.ei_id;
    this.postData.type=this.request.type;
  },
  methods: {
    add() {
      this.$refs.table.datalist.push({type:this.request.type,ei_id:this.request.ei_id,});
    },
    async del(item)
    {
      if(item.id!=undefined)
      {
        await elm.post("/business/my/ei/credentials/Delete",{ id: item.id});
      }
      this.$refs.table.datalist = this.$refs.table.datalist.filter(p => !(p==item));
    },
    async submit()
    {
      var ret = await elm.post("/business/my/ei/credentials/Save",
          {items:this.$refs.table.datalist,ei_id:this.request.ei_id,type:this.request.type});
      if(ret>0)
      {
        this.close();
        this.v("保存成功。");
        this.request.callVue.init_credentials(this.request.type);
      }
    }
  }
}
</script>
